package teehee.UI;

import teehee.DB.DB;
import teehee.homepage.R;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

public class AddNewTabs extends TabActivity implements OnTabChangeListener {
	
	public static DB entry;
	public static boolean goHistoryPage = false;
	TabHost tabHost;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab);
        
        /* TabHost will have Tabs */
        tabHost = (TabHost)findViewById(android.R.id.tabhost);
        tabHost.setOnTabChangedListener(this);
        
        /* TabSpec used to create a new tab. 
         * By using TabSpec only we can able to setContent to the tab.
         * By using TabSpec setIndicator() we can set name to tab. */
        
        /* tid1 is firstTabSpec Id. Its used to access outside. */
        TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
        TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
        
        /* TabSpec setIndicator() is used to set name for the tab. */
        /* TabSpec setContent() is used to set content for a particular tab. */
        firstTabSpec.setIndicator("WOD", getResources().getDrawable(R.drawable.icon_tab));
        secondTabSpec.setIndicator("Exercise", getResources().getDrawable(R.drawable.icon_tab2));
        
        firstTabSpec.setContent(new Intent(this, AddNewWOD.class));
        secondTabSpec.setContent(new Intent(this, AddNewExercise.class));
        
        /* Add tabSpec to the TabHost to display. */
        tabHost.addTab(firstTabSpec);
        tabHost.addTab(secondTabSpec);
        
        for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
        {
        	tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#093055"));
        }
        
        tabHost.getTabWidget().setCurrentTab(0);
        tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#E6F4FF"));
        
    }
    
    public void onTabChanged(String tabId) {
		// TODO Auto-generated method stub
		for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
        {
        	tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#E6F4FF"));
        } 
				
		tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#093055"));
	}
    
    @Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        if ((keyCode == KeyEvent.KEYCODE_MENU))
        { 
        	//setContentView(R.layout.main);
        	Intent homep = new Intent(AddNewTabs.this, MainPage.class);
    		startActivity(homep);
            return true;
        }
        
        if ((keyCode == KeyEvent.KEYCODE_SEARCH))
        { 
        	//setContentView(R.layout.main);
        	Intent homep = new Intent(AddNewTabs.this, SearchPage.class);
    		startActivity(homep);
            return true;
        }
        
        return super.onKeyDown(keyCode, event);    
    } 
}
